<?php
class Application_Form_frmTarefaPadrao extends ZendX_JQuery_Form
{

    public function init()
    {
        $decorator_hidden_element = array(
            'ViewHelper',
            array(array('data'=>'HtmlTag'), array('tag' => 'td')),
            array(array('row'=>'HtmlTag'),array('tag'=>'tr','style'=>'display:none'))
           );
        
        $decorator_element = array(
            'ViewHelper',
            'Description',
            'Errors',
            array(array('data'=>'HtmlTag'), array('tag' => 'td')),
            array('Label',  array('tag' => 'td', 'style'=>'float:right;')),
            array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
           );
        
        $decorator_submit = array(
           'ViewHelper',
           'Description',
           'Errors', array(array('data'=>'HtmlTag'), array('tag' => 'td',
           'colspan'=>'2','align'=>'center')),
           array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
        );

        $decorator_form = array(
            'FormElements',
            array(array('data'=>'HtmlTag'),array('tag'=>'table')),
            'Form'
        );
  
        $this->setAttrib('accept-charset', 'utf-8')
            ->setName('tarefa');
        
        // campo id
        $id = new Zend_Form_Element_Hidden('id');
        $id->addFilter('Int');
        $id->setDecorators($decorator_hidden_element);
        $this->addElement($id);

        // tarefa_pai
        $tarefa_pai = new Zend_Form_Element_Hidden('tarefa_pai');
        $tarefa_pai->addFilter('Int');
        $tarefa_pai->setValue(0);
        $tarefa_pai->setDecorators($decorator_hidden_element);
        $this->addElement($tarefa_pai);

        // campo tipo_id
        $tipo_id = new Zend_Form_Element_Hidden('tipo_id');
        $this->addElement($tipo_id);
/*        $tipos = new TarefasTipo();
        $tipo_id = new Zend_Form_Element_Select('tipo_id');
        $tipo_id->setLabel('Tipo');
        $result = $tipos->fetchAll();
        foreach($result as $tipo):
            $tipo_id->addMultiOption($tipo->id,$tipo->tipo);
        endforeach;
        $tipo_id->setDecorators($decorator_element);
        $this->addElement($tipo_id);
*/        
        // campo categoria_id
        $categorias = new Categorias();
        $categoria_id = new Zend_Form_Element_Select('categoria_id');
        $categoria_id->setLabel('categoria');
        $result = $categorias->fetchAll();
        foreach($result as $categoria):
            $categoria_id->addMultiOption($categoria->id,$categoria->categoria);
        endforeach;
        $categoria_id->setDecorators($decorator_element);
        $this->addElement($categoria_id);
        
        //campo tarefa
        $tarefa = new Zend_Form_Element_Text('tarefa');
        $tarefa->setLabel('tarefa')
            ->setAttrib('size', 50)
            ->setRequired(true)
            ->addFilter('StripTags')
            ->addFilter('StringTrim')
            ->addValidator('NotEmpty')
            ->setDecorators($decorator_element);
        $this->addElement($tarefa);

        //campo obs
        $obs = new Zend_Form_Element_Textarea('obs');
        $obs->setLabel('Obs')
            ->setAttrib('cols', 50)
            ->setAttrib('rows', 11)
            ->setDecorators($decorator_element);
        $this->addElement($obs);

        //campo duracao
        $duracao = new Zend_Form_Element_Text('duracao');
        $duracao->setLabel('duração (dias)')
            ->addFilter('LocalizedToNormalized')
            ->setAttrib('size', 10)
            ->setDecorators($decorator_element);
        $this->addElement($duracao);

        //campo link
        $link = new Zend_Form_Element_Text('link');
        $link->setLabel('link')
            ->setAttrib('size', 50)
            ->setDecorators($decorator_element);
        $this->addElement($link);

        // campo ativo
        $ativo_id = new Zend_Form_Element_Select('ativo');
        $ativo_id->setLabel('ativo');
        $ativo_id->addMultiOption(1,'ativo');
        $ativo_id->addMultiOption(0,'inativo');
        $ativo_id->setDecorators($decorator_element);
        $this->addElement($ativo_id);
        
        $decorator_data_element = array(
            'UiWidgetElement',
            'Description',
            'Errors',
            array(array('data'=>'HtmlTag'), array('tag' => 'td')),
            array('Label',  array('tag' => 'td', 'style'=>'float:right;')),
            array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
           );
        
        // botão submit
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setAttrib('id', 'submitbutton')
            ->setDecorators($decorator_submit);
        $this->addElement($submit);
        
        $this->setDecorators($decorator_form);
    }


}

